<template>
    <el-container>
      <el-header style="height: 47px;">
        <p>功能角色信息列表</p>
      </el-header>
      <el-main>
        <el-row class="btnGroup">
          <el-button class="twoBtn" @click="addRoles"><span>添加</span>
            <i class="el-icon-plus"></i>
          </el-button>
        </el-row>
        <el-table
          :data="tableData.list"
          style="width:100%"
          tooltip-effect="dark"
          height="500"
          highlight-current-row
          @row-click="tableClickChange"
          stripe
          v-loading="loading"
        >
          <el-table-column  align="center"  prop="rolename" label="角色名称"></el-table-column>
          <el-table-column  align="center"  prop="rolenote" label="角色说明"></el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            width="100">
            <template slot-scope="scope">
              <el-button type="text" @click.capture.stop="editRoles(scope.row)" size="small">编辑</el-button>
              <el-button type="text" @click.capture.stop="delRoles(scope.row)" size="small">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
      <el-footer>
        <el-pagination
          background
          layout="total,sizes,prev,pager,next,jumper"
          :total="dataCount"
          :page-sizes="[10,20,30,50]"
          :page-size="dataPageSize"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          style="margin-top: 10px;"
        ></el-pagination>
      </el-footer>
    </el-container>
</template>

<script>
  import { delRoles } from '../../../api/system/functionRoles'
  import { getNum } from '../../../api/public/searchUnit'

  export default {
    name: 'functionRolesTable',
    props: ['tableData', 'tableLoading'],
    data() {
      return {
        loading: false,
        tableDatas: [],
        dataCount: 0,
        dataPageSize: 10,
        checkModel: ''
      }
    },
    watch: {
      tableLoading: function(val) {
        this.loading = val
      },
      tableData: function() {
        this.dataCount = this.tableData.count
        this.dataPageSize = this.tableData.pageSize
      }
    },
    methods: {
      addRoles: function() {
        this.$emit('addClick', true)
      },
      editRoles: function(row) {
        this.checkModel = Object.assign({}, row) // copy obj
        this.$emit('editClick', [this.checkModel, true])
      },
      delRoles: function(row) {
        this.$confirm('此操作将永久删除选中的记录,是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delRoles(row).then(res => {
            this.$emit('randnum', getNum())
            this.$message({
              message: '删除成功',
              type: 'success'
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
      tableClickChange: function(val) {
        this.$emit('treeChange', [val, true])
      },
      handleCurrentChange: function(val) {
        this.$emit('page_num', val)
      },
      handleSizeChange(val) {
        this.$emit('sizePage', val)
      }
    }
  }
</script>

<style scoped>
  .el-main{
    padding: 0;
    margin-top: 24px;
    margin-left: 24px;
  }
  .el-header p{
    font-family: MicrosoftYaHei;
    font-size: 13px;
    margin-top: 22px;
    color: #7F8CA6;
  }
  .el-header{
    padding:0;
    margin-left: 24px;
    margin-right: 24px;
    border-bottom: 1px solid #E1E1E1;
  }
  .btnGroup{
    margin-bottom: 16px;
  }
  .btnGroup > .twoBtn{
    width: 64px;
    height:24px;
    padding: 4px 20px;
    border: 1px solid #409eff;
    font-family: MicrosoftYaHei;
    color: #fff;
    font-size: 12px;
  }
  .btnGroup > .el-button span{
    display: none;
  }
  .btnGroup > .el-button:hover{
    background-color: #409EFF;
  }
  .btnGroup > .el-button:hover span{
    display: block;
  }
  .btnGroup > .el-button:hover i{
    display: none;
  }
  .el-button i{
    color: #409eff;
  }
  .el-footer{
    text-align: right;
  }
</style>
